#ifndef __losor_event_h__
#define __losor_event_h__

#include <inttype.h>

#ifdef __cplusplus
extern "C" {
#endif

extern int push_task( void *task, int priority );
extern int push_task_sys( void *task, int priority );

typedef struct _event
{
    uint64 id;
    char *para;
    int para_len;
    struct _event *parent;
} event ;

long getsp( );
event* event_create_raw( uint64 id, event *parent, long sp, ... );
void event_destroy( event *e );
event* current_event();
void update_current_event( event *e );
void process( void *func, event *e );

#define raise_event( id, priority, ... )                            \
    {                                                               \
        long __internal_event_arg0;                                 \
        event *__internal_event_arg1;                               \
        __internal_event_arg0 = getsp();                            \
        __internal_event_arg1 = event_create_raw( id,               \
            current_event(), __internal_event_arg0, __VA_ARGS__ );  \
        push_task( __internal_event_arg1, priority );               \
    }

#define USER_EVENT      10000

#ifdef __cplusplus
};
#endif

#endif // __losor_event_h__
